#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{
	pid_t pid = 0;

	pid = fork();

	if(pid == 0)
	{
		int i = 0;
		printf("pid = %d\n",getpid());
		while(i < 50)
		{
			printf("child process\n");
			sleep(1);
			i = i + 1;
		}
		exit(23);
	}else if(pid < 0)
	{
		printf("fork error\n");
		exit(-1);
	}

	printf("father:%d\n",getpid());

	int status;
	wait(&status);

	if(WIFEXITED(status))
	{
		printf("child process is existed normal\n");
		printf("%d\n",WEXITSTATUS(status));
	}else if(WIFSIGNALED(status))
	{
		printf("child process is existed abnormal\n");
		printf("%d\n",WTERMSIG(status));
	}


	return 0;
}
